﻿@{
     WebSecurity.RequireAuthenticatedUser();
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "REPORTS";
    Page.Region = RefDataManager.GetRegionLkUpVal();
    Page.IDType = RefDataManager.GetIDTypeLkUpVal();
    var pbs = RefDataManager.GetPartnerBankLkUpVal();
    var sols = RefDataManager.GetSolicitorLkUpVal();
    var custStatus = RefDataManager.GetCustStatLkUpVal();
    var custClass = RefDataManager.GetCustClassLkUpVal();
    var campaign = RefDataManager.GetCampaignLkUpVal();
    var country = RefDataManager.GetCountryValues();
    var ccStat = RefDataManager.GetCashCardStatLkUpVal();
    var ccDelStat = RefDataManager.GetCardDelLkUpVal();
    var docStat = RefDataManager.GetDocStatLkUpVal();
    var delCourier = CourierManager.GetCourierLkUpValues();
    var region = RefDataManager.GetRegionLkUpVal(); 
}

<style type="text/css">
/** { font-family: Verdana; font-size: 96%; }*/
label { width: 15em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
<script>
    $(function(){
         toggleFields(false);
         
        GetLookUp("#country","#state","state");
        
        $("#searchDate").datepicker({
                changeMonth:true,
                changeYear:true,
                showButtonPanel:true,
                dateformat:'dd/mm/yy',
                yearRange:'-100:+0',
                minDate: new Date(1930,1-1,1),
                maxDate: new Date(2012,12-1,31)
                });
    
        $("#reportType").change(function(){
            displayReportParams();
            
        });
        
        $("#search").click(function(){
            loadGrid();
        });
        showSpinner();
        
        
         $("#custName").autocomplete({
        source:getRefByDS(),
        minLength:0,
        focus: function( event, ui ) {
				$("#custName").val( ui.item.label );
				return false;
			},
        select: function( event, ui ) {
    			$("#custName").val( ui.item.label );
				$("#custId").val( ui.item.value );
		        
				return false;
			}
            
    }).data("autocomplete")._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a>" + item.label  + "</a>" )
				.appendTo( ul );
		};    
        
    });
function toggleFields(f){
    $("#dateField").toggle(f);
    $("#pbRef").toggle(f);
    $("#solRef").toggle(f);
    $("#buttons").toggle(f);
    $("#custStatus").toggle(f);
    
    
    
}    

function toggleDate(flag){
     $("#dateField").toggle(flag);
}

function togglePB(flag){
    $("#pbRef").toggle(flag);
}

function toggleSol(flag){
     $("#solRef").toggle(flag);
}

function toggleButtons(flag){
    $("#buttons").toggle(flag);
}

function toggleCStatus(flag){
    $("#custStatus").toggle(flag);
}
    
function loadGrid(){
    var sol = $("#sol").val();
    var cStatus = $("#cStatus").val();
    var pbank = $("#pb").val();
    var sDate = $("#searchDate").val();
    var rType = $("#reportType").val();
    var params = (sol!="0")?"?solicitor="+sol:"?solicitor=0";
    params+=(cStatus!="0")?"&cStatus="+cStatus:"&cStatus=0";
    params+=(pbank!="0")?"&pbank="+pbank:"&pbank=0";
    params+=(rType!="0")?"&report="+rType:"&report=0";
    params+=(sDate!="")?"&sDate="+sDate:"&sDate="+defaultDate();
    
    var dummy = new Date().getTime();
    $.get("/Reports/ReportGrid"+params+"&dummy="+dummy,function(data){
        $("#grid").empty();
        $("#grid").html(data); 
    });
  //  $("#grid").load("/Reports/ReportGrid"+params);
}    

function defaultDate(){
    return "01/01/1900";
}

function displayReportParams(){
    $("#searchParams").empty();
    var sp= $("#searchParams");
    var type = $("#reportType").val();
    switch(parseInt(type)){
        case 1:
           toggleDate(true);
           togglePB(true);
           toggleSol(false);
          toggleCStatus(false)
           toggleButtons(true);
        break;
        case 2:
           toggleDate(true);
           toggleSol(true);
           togglePB(false);
           toggleCStatus(false)
           toggleButtons(true);
         
        break;
        case 3:
          toggleDate(true);
          togglePB(true);
          toggleSol(false);
          toggleCStatus(false)
          toggleButtons(true);
        break;
        case 4:
          toggleDate(true);
          togglePB(true);
          toggleSol(true);
          toggleCStatus(false)
          toggleButtons(true);
        break;
       
    }
}
</script>
<form id="reportForm" name="reportForm">
<div id="spinner" class="spinnerContent" style="display:none;border:1px solid black">
                    <img id="img-spinner" src="@Href("/images/ajax-loader.gif")" alt="Loading"/>
                    <p>Generating report please wait...</p>
                </div>
                <div id="spinnerBG"></div>    
<fieldset class="ui-widget ui-widget-content">
<legend>Reports</legend>
<div>
  <p>
  <label for="reportType">Report Type:</label>
  <select name="reportType" id="reportType">
    <option value="0">Choose Report</option>
    <option value="1">Cash Card Master List</option>
    <option value="2">Validation List</option>
    <option value="3">Pending Application List</option>
    <option value="4">Applications In-Progress</option>
</select>
  
</p>    
</div>    
  
   <div id="searchParams">
    
</div>
 <div id="dateField">
    <p>
       <label for="searchDate">Date:</label>
    <input type="text" id="searchDate" name="searchDate"/> 
    </p>
    
</div>   
 <div id="pbRef" >
 <p>
     <label for="pb">Partner Bank</label>
 <select name="pb" id="pb">
    <option value="0">Choose Partner Bank</option>
    @foreach(var pb in pbs){
        <option value="@pb.RefID">@pb.RefDesc</option>
    }
</select>   
</p>   

</div> 
 <div id="solRef">
 <p>
  <label for="sol">Solicitor</label>
 <select name="sol" id="sol">
    <option value="0">Choose Solicitor</option>
    @foreach(var s in sols){
        <option value="@s.RefID">@s.RefDesc</option>
    }
</select>      
</p>   
 
</div>   
<div id="custStatus">
 <p>
 <label for="custStatus">Customer Status:</label>
    <select name="cStatus" id="cStatus">
    <option value="0">Choose Customer Status</option>    
    @foreach(var c in custStatus){
        <option value="@c.RefID">@c.RefDesc</option>
    }
</select>      
</p>   
    
</div>    
 <div id="buttons">
        <input type="button" id="search" value="search"/>
    </div>
    <br/>
 </fieldset>
   
<div id="grid">
    
</div>
</form>